﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Meraz.Core.Model;

namespace Meraz.Core.Repositories
{
    public interface IRoleRepository : IRepository<Role, int> {
        List<Role> Get(string applicationName);
        Role Get(string applicationName, string roleName);
    }
    public class RoleRepository : EFRepositoryBase<Role, int>, IRoleRepository
    {
        public RoleRepository() : base() {}
        public RoleRepository(Data.IMerazContext context) : base(context) { }

        public override Role GetById(int id)
        {
            return this.context.Roles.Where(where1 => where1.ID == id).FirstOrDefault();
        }
        public Role Get(string applicationName, string roleName)
        {
            return this.context.Roles.Where(where1 => where1.RoleName == roleName && where1.ApplicationName == applicationName).FirstOrDefault();
        }

        public List<Role> Get(string applicationName)
        {
            return this.context.Roles.Where(where1 => where1.ApplicationName == applicationName).ToList();
        }

        public override void Add(Role entity)
        {
            this.context.AddToRoles(entity);
        }

        public override void Delete(Role entity)
        {
            this.context.Roles.DeleteObject(entity);
        }

        public override List<Role> All()
        {
            return this.context.Roles.ToList();
        }
    }
}
